<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./src/vue.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item,i) in items" :key="item.id">{{item.title}}</li>
      </ul>
      <button @click="add">add</button>
    </div>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {
          items: [{id: 1, title: "小明1"}, {id: 2, title: "小明2"}],
        },
        methods: {
          add() {
            // 1. push()
            // this.items.push({
            //   id: parseInt(Date.now() / 1000),
            //   title: parseInt(Date.now() / 1000)
            // });

            // 2. unshift()
            this.items.unshift({
              id: parseInt(Date.now() / 1000),
              title: parseInt(Date.now() / 1000)
            });
          },
        },
      });
      // 1. key的值能够为索引？
      // 2. key是否为必须属性？
    </script>
  </body>
</html>
